define(['jquery', 'bootstrap', 'select2', 'validate', 'validate.en', 'koala-search', 'shiftform', 'modalSearch',
        'datetimepicker', 'datetimepickerCN'],
function($, validate) {
  return {
    
    init: function() {
      this.initPage();
      this.initWarehouse();
      this.initClient();
      this.initVehicle();
      this.initManufacturer();
    },
    
    initPage: function(){
        $('.btn-remove').on('click', function(e){
            $('input').val('');
        });
        
        $(document).find('form').bt_validate();
        
        $('select[name="organizationId"]').select2({
          theme: "classic",
          placeholder : '请选择',
          minimumResultsForSearch : -1,
          allowClear : true,
        });
        
        $('.date').datetimepicker({
          format: 'yyyy-mm-dd',
          autoclose: true,
          language: 'zh-CN',
          todayBtn: 'linked',
          startDate: '${today}',
          todayHighlight: true,
          pickerPosition: 'bottom-right',
          minView: 'month'
        });
    },
    
    initLoadPlace: function() {
        
        $('[data-target="#modal-search-fromLoadPlace"]').modalsearch({
              url: window.__CTX__.root + '/load-places/query',
              tableColumns: ['出发地代码', '出发地名称'],
              tableValues: ['code', 'name'],
              displayValues: ['code', 'name'],
              values: ['id']
        });
        
        $('[data-target="#modal-search-toLoadPlace"]').modalsearch({
              url: window.__CTX__.root + '/load-places/query',
              tableColumns: ['到达地代码', '到达地名称', 'id'],
              tableValues: ['code', 'name', 'id'],
              displayValues: ['code', 'name'],
              values: ['id']
        });
        
        var options = {
              time: 1000,
              url: window.__CTX__.root + "/load-places/query",
              queryName: "code",
              value: ["id"],
              display: ["code", "name"]
        }
        
        $('.fromLoadPlace-search').koalaSearch(options);
        $('.toLoadPlace-search').koalaSearch(options);
        
        $(document).on("koala.search.value.changed", ".fromLoadPlace-search, .toLoadPlace-search", function(){
              console.log($(this).next().val());
              // TODO 其他查询后的逻辑
        })
      }
  }
})